package main

import (
	"fmt"
	"math"
	"math/cmplx"
)

var (
	aa = 3
	bb = "hello"
	cc = true
)

func varZeroValue() {
	var a int
	var s string
	fmt.Printf("%d, %q \n", a, s)
}

func varInitialValue() {
	var a, b = 3, 4
	var s = "hello"
	fmt.Println(a, b, s)
}

// 变量类型推断
func varTypeDeduction() {
	var a, b, c, d = 3, 3.14, true, "hello"
	fmt.Println(a, b, c, d)
}

func varShorter() {
	a, b, c, d := 3, 3.14, true, "hello"
	b = 3.15
	fmt.Println(a, b, c, d)
}

func euler() {
	fmt.Printf("%.3f \n", cmplx.Exp(1i*math.Pi)+1)
}

// 三角形计算边长
func triangle() {
	var a, b = 3, 4
	fmt.Println(calcTriangle(a, b))
}
func calcTriangle(a int, b int) int {
	var c int
	c = int(math.Sqrt(float64(a*a + b*b)))
	return c
}

func constants() {
	const (
		filename = "abc.txt"
		a, b     = 3, 4
	)

	var c int
	c = int(math.Sqrt(float64(a*a + b*b)))
	fmt.Println(filename, c)
}

// 枚举类型
func enums() {
	const (
		cpp = iota
		_
		python
		golang
	)
	fmt.Println(cpp, python, golang)

	const (
		b = 10 * iota
		ab
		cb
		db
	)
	fmt.Println(b, ab, cb, db)
}

func main() {
	fmt.Println("全局变量: ", aa, bb, cc)
	varZeroValue()
	varInitialValue()
	varTypeDeduction()
	varShorter()
	euler()
	triangle()
	constants()
	enums()
}
